package com.bwie.controller;
import com.bwie.pojo.ProdFile;
import com.bwie.pojo.Prods;
import com.bwie.service.ProdsService;
import com.bwie.service.impl.ProdsServiceImpl;
import com.bwie.utils.R;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.List;

/**
* 产品表(t_prods)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/shop/index/")
@Api(tags = "产品模块")
public class ProdsController {
/**
* 服务对象
*/
    @Autowired
    private ProdsService prodsService;



    @ApiOperation("缓存存入字典表")
    @PostMapping("createDictToRedis")
    @PostConstruct
    public R createDictToRedis(){
        return prodsService.createDictToRedis();
    }

    @ApiOperation("缓存获取字典数据")
    @GetMapping("getDictValueByRedis/{dictPid}")
    public R getDictValueByRedis(@PathVariable("dictPid")Integer dictPid){
        return prodsService.getDictValueByRedis(dictPid);

    }
    @ApiOperation("获取品牌下拉列表")
    @PostMapping("getSelectBrand")
    public R getSelectBrand(){
        return prodsService.getSelectBrand();
    }
    @ApiOperation("校验商品SPU重复")
    @PostMapping("checkIfRepeat")
    public R checkIfRepeat(@RequestBody Prods prods){
        return prodsService.checkIfRepeat(prods);
    }
    @ApiOperation("完成商品添加")
    @PostMapping("saveProduct")
    public R saveProduct(@RequestBody @Validated Prods prods){
        return prodsService.saveProduct(prods);
    }


    @ApiOperation("商品列表")
    @PostMapping("joinSelectProdList")
    public R joinSelectProdList(@RequestBody Prods prods){
        return prodsService.joinSelectProdList(prods);
    }

    @ApiOperation("保存商品附件")
    @PostMapping("saveProFileOk")
    public R saveProFileOk(@RequestBody @Validated ProdFile prodFile){
        return prodsService.saveProFileOk(prodFile);
    }

    @ApiOperation("商品批删操作")
    @PostMapping("deleteGoodsBatch")
    public R deleteGoodsBatch(@RequestBody List<Integer> ids){
        return prodsService.deleteGoodsBatch(ids);
    }
    @ApiOperation("es查询商品列表")
    @PostMapping("joinSelectProdListByEs")
    public R joinSelectProdListByEs(@RequestBody Prods prods){
        return prodsService.joinSelectProdListByEs(prods);
    }

    @ApiOperation("批量上架商品")
    @PostMapping("barchUpProd")
    public R batchUpProd(@RequestBody List<Integer> ids){
        return prodsService.batchUpProd(ids);
    }
}

